<!DOCTYPE html>
<html lang="en" class="no-js" xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
	layout:decorator="layout">
<head>
<title>添加商品</title>
<style> 

  .white_content {  
  display: none;  position: absolute;  top: 25%;  left: 25%;  width: 50%;  height: 50%;  padding: 16px;  
  border: 16px solid bule;  background-color: white;  z-index:1002;  overflow: auto;  
  } 
  ul { list-style:none;
	} 
</style> 
</head>
<body id="check_goodsSN_form" onload="load()">
<div layout:fragment="content">
<link th:href="@{/plugins/bootstrap-modal/css/bootstrap-modal-bs3patch.css}" rel="stylesheet" href="plugins/bootstrap-modal/css/bootstrap-modal-bs3patch.css"/>
<link th:href="@{/plugins/bootstrap-modal/css/bootstrap-modal.css}" rel="stylesheet" href="plugins/bootstrap-modal/css/bootstrap-modal.css"/>
<link th:href="@{/plugins/zTree/css/zTreeStyle/zTreeStyle.css}" rel="stylesheet" href="plugins/zTree/css/zTreeStyle/zTreeStyle.css"/>
<script th:src="@{/plugins/zTree/js/jquery.ztree.core-3.5.js}" src="plugins/zTree/js/jquery.ztree.core-3.5.js" type="text/javascript"></script>	

		<div class="row">
			<div class="col-md-12">
				<div class="btn-group pull-right">
					<a href="index.html" th:href="@{/goods/goods/index}"
						id="Link_cancel" class="btn green">返回<i
						class="fa fa-arrow-circle-o-left"></i></a>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-12">
				<div class="form">
					<form role="form" th:action="@{/goods/goods/save}" id="goods_form_check" name="theForm"
						th:object="${goods}" method="post" class="form-horizontal"
						enctype="multipart/form-data">
						<h4 class="form-section">商品基本信息</h4>
						<input type="hidden" id="goodsId" th:field="*{id}" th:value="${id}"/>
						<input type="hidden" name="goodImage" id="goodsValue" th:field="*{goodsPic}" />
						<input type="hidden" name="thumbImage" id="longValue" th:field="*{thumbGoodsPic}" />
						<input type="hidden" name="longGoodsImage" id="thumbValue" th:field="*{longGoodsPic}" />
						<input type="hidden" th:field="*{mark}" id="markValus" value=""/>
						<div class="form-body">

							<div class="form-group"
								th:class="${#fields.hasErrors('name')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">商品名称<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="商品名称"
										th:field="*{name}"  id="goods_name" /> <span
										class="help-block" th:if="${#fields.hasErrors('name')}"
										th:errors="*{name}">商品名称不能为空</span>
								</div>
							</div>

							<div class="form-group" >
								<label class="control-label col-md-3">促销标题</label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="促销标题" th:field="*{title}"  id="goods_title" />
								</div>
							</div>

							<div class="form-group" th:class="${#fields.hasErrors('goodsSN')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">商品货号<span class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="商品货号" th:field="*{goodsSN}"  id="goods_goodsSN" />
									<span  class="help-block" th:if="${#fields.hasErrors('goodsSN')}" th:errors="*{goodsSN}" >
									</span>
								</div>
							</div>
							
							<div class="form-group" th:class="${#fields.hasErrors('brandId')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">品牌名称<span class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
								
									<select id="selt_brandType" name="selt_brandType"  th:remove="none" class="form-control" th:field="*{brandId}" >
										<option th:value="0">请选择品牌名称</option>
										<option th:each="eachValue : ${brands}"   th:value="${eachValue.id}" th:text="${eachValue.name}"></option>
									</select>
									<span class="help-block" th:if="${#fields.hasErrors('brandId')}" th:errors="*{brandId}">商品名称不能为空</span>
								</div>
							</div>

							<!-- <div class="form-group" th:class="${#fields.hasErrors('categoryId')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">商品分类<span class="required" aria-required="true">* </span></label>
								<div class="col-md-4" >
									<select id="goodsCategoryId" name="goodsCategoryId" th:field="*{categoryId}" th:remove="none" class="form-control" onchange="changeCate(this)">
					            	<option th:value="0">请选择商品分类</option>
					                <option th:each="eachValue : ${categorys}"  th:value="${eachValue.id}" th:text="${eachValue.name}"></option>
					            	</select>
					            	<span class="help-block" th:if="${#fields.hasErrors('categoryId')}" th:errors="*{categoryId}">商品分类不能为空</span>	
								</div>
							</div> -->
							
							<div class="form-group" th:class="${#fields.hasErrors('categoryId')}? 'form-group has-error' : 'form-group'">
							<label class="control-label col-md-3">商品分类<span class="required" aria-required="true">* </span></label>
							<div class="col-md-4" id="categoryCheck">
							
					            <select th:field="*{categoryId}" th:remove="all-but-first" class="form-control"  style="display:none;" >
					                <option th:each="eachValue : ${categorys}" th:value="${eachValue.id}" th:text="${eachValue.name}"  style="display:none" ></option>
					            </select>

									
								<button id="treebutton" class="btn btn-default dropdown-toggle" type="button"  data-toggle="dropdown">
									分类 <i class="fa fa-angle-down"></i>
								</button>
								<div class="dropdown-menu dropdown-content input-large">
									<div id="category_tree" role="menu">
									</div>
								</div>

								
 					            <span class="help-block" th:if="${#fields.hasErrors('categoryId')}" th:errors="*{categoryId}">顶级分类不可以修改</span>
										
							</div>
						</div>

							<div class="form-group"
								th:class="${#fields.hasErrors('shopPrice')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">本店售价<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="本店售价"  th:field="*{shopPrice}"  id="goods_shopPrice" />
									<span class="help-block" th:if="${#fields.hasErrors('shopPrice')}" th:errors="*{shopPrice}">本店售价不能为空</span>
								</div>
							</div>

							<div class="form-group"
								th:class="${#fields.hasErrors('marketPrice')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">市场售价<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="市场售价" th:field="*{marketPrice}" id="goods_marketPrice" /> <span class="help-block"
										th:if="${#fields.hasErrors('marketPrice')}"
										th:errors="*{marketPrice}">市场售价不能为空</span>
								</div>
							</div>
							
							<div class="form-group" th:class="${#fields.hasErrors('goodsPic')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3" >商品图片<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-3">
								<input type="file" name="goodImage" id="goodsp" class="form-control"   placeholder="商品图片" onchange="fileChange(this,1);"/>
								<span class="help-block" th:if="${#fields.hasErrors('goodsPic')}" th:errors="*{goodsPic}">商品图片不能为空</span>
								</div>
								<div id="goodpic">
       							 <a class="glyphicon glyphicon-ok" title="Click to view larger image" href="javascript:void(0)" onclick="document.getElementById('goodshow').style.display='block';document.getElementById('fade').style.display='block'">
      							  </a>
      						   </div>
								
								
							</div>
							
							<div class="form-group" th:class="${#fields.hasErrors('thumbGoodsPic')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">商品缩略图<span class="required" aria-required="true">* </span></label>
								<div class="col-md-3">
								<input type="file"  name="thumbImage" id="thumbPic"   class="form-control" placeholder="商品缩略图" onchange="fileChange(this,2);"/> 
								<span class="help-block" th:if="${#fields.hasErrors('thumbGoodsPic')}" th:errors="*{thumbGoodsPic}">本店售价不能为空</span>
								<label ><input th:field="*{checkPic}" th:value="checkThumbpic"  id="checkVal" checked="checked"  type="checkbox" onclick="handleAutoThumb(this.checked)"/>自动生成商品缩略图</label>
								</div>
								<div  style="display: none;"><input type="file"  name="thumbImage" class="form-control"/> </div>
								
								<div id="thumbpic">
        						<a class="glyphicon glyphicon-ok" title="Click to view larger image" href="javascript:void(0)" onclick="document.getElementById('thumbshow').style.display='block';document.getElementById('fade').style.display='block'">
        						</a>
        						</div>
								
							</div>
							
							<div class="form-group" th:class="${#fields.hasErrors('longGoodsPic')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">商品长图<span class="required" aria-required="true">* </span></label>
								<div class="col-md-3">
								<input type="file"   name="longGoodsImage" id="longsp" class="form-control" placeholder="商品长图" onchange="fileChange(this,3);"/></div>
							    <span class="help-block" th:if="${#fields.hasErrors('longGoodsPic')}" th:errors="*{longGoodsPic}">本店售价不能为空</span>
							    <div id="longpic">
        						<a class="glyphicon glyphicon-ok" title="Click to view larger image" href="javascript:void(0)" onclick="document.getElementById('longshow').style.display='block';document.getElementById('fade').style.display='block'">
       							 </a>
        						</div>
							</div>
							
							<!-- SKU 开始 -->
							<div class="form-group" >
							<label class="control-label col-md-3">商品规格<span class="required" aria-required="true">* </span></label>
							<div class="col-md-8">
								<div id="div_sku_grid" th:include="goods/goods/sku_table">
								</div>
                            </div>
                            </div>
							<!-- SKU 结束 -->
							
							
	
							<div class="form-group">
								<label class="control-label col-md-3">商品视频</label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="商品视频"
										th:field="*{goodsVideo}" id="goods_goodsVideo" />
								</div>
							</div>


							<div class="form-group">
								<label class="control-label col-md-3">商品详情</label>
								<div class="col-md-4">
									<textarea id="textarea_content" rows="4" type="text"
										class="form-control" placeholder="内容" th:field="*{content}" />
								</div>
							</div>

							<div class="form-group"
								th:class="${#fields.hasErrors('goodsStore')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">商品库存<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="库存"
										th:field="*{goodsStore}" id="goods_goodsStore"  readOnly="true" />
									<span class="help-block"
										th:if="${#fields.hasErrors('goodsStore')}"
										th:errors="*{goodsStore}">库存不能为空</span>
								</div>
							</div>

							<div class="form-group">
								<label class="control-label col-md-3">库存预留量<span class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="库存预留量" th:field="*{reservedStore}" id="goods_reservedStore" maxlength="8"/>
								</div>
							</div>

							<div class="form-group">
								<label class="control-label col-md-3">虚拟销售数量<span class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="虚拟销售数量" th:field="*{virtualSales}" id="goods_virtualSales" maxlength="8"/>
								</div>
							</div>
							
							<div class="form-group">
								<label class="control-label col-md-3">真实销售数量<span class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="真实销售数量" th:field="*{realSales}" id="goods_realSales" maxlength="8"/>
								</div>
							</div>

							
							<div class="form-group">
								<label class="control-label col-md-3">加入推荐</label>
								<div class="col-md-9">
									<div class="checkbox-list" >
										<label class="checkbox-inline" th:each="SelectRecommend : ${selectRecommends}"> 
										<input type="checkbox"   th:field="*{selectRecommendList}"  name="selectRecommend" th:value="${SelectRecommend}" th:text="${SelectRecommend.description}" id="goods_selectRecommend" />
										</label>	
									</div>	
								</div>
							</div>
						
							

							<div class="form-group">
								<label class="control-label col-md-3">是否上架<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<div class="radio-list">
										<label class="radio-inline"><span><input
												id="radio_displayed_1" type="radio" value="1" checked=""
												th:field="*{displayed}" /></span> 是</label> <label class="radio-inline"><span><input
												id="radio_displayed_2" type="radio" value="0"
												th:field="*{displayed}" /></span> 否</label>
									</div>
								</div>
							</div>

							<div class="form-group">
								<label class="control-label col-md-3">是否为虚拟商品</label>
								<div class="col-md-4">
									<div class="radio-list">
										<label class="radio-inline"><span><input
												id="radio_displayed_1" type="radio" value="1" checked=""
												th:field="*{whether}" /></span> 是</label> <label class="radio-inline"><span><input
												id="radio_displayed_2" type="radio" value="0"
												th:field="*{whether}" /></span> 否</label>
									</div>
								</div>
							</div>

							<div class="form-group">
								<label class="control-label col-md-3">商品简单描述</label>
								<div class="col-md-4">
									<textarea id="goods_shortDescription" rows="4" type="text"
										class="form-control" placeholder="商品简单描述"
										th:field="*{shortDescription}" maxlength="254"/>
								</div>
							</div>
							
							<div class="form-group">
								<label class="control-label col-md-3">商品关键词</label>
								<div class="col-md-4">
								<input type="text" class="form-control" placeholder="商品关键词" maxlength="100" th:field="*{goodsTag}"  id="goods_goodsTag" /> 
									
								</div>
							</div>

							<div class="form-group">
								<label class="control-label col-md-3">排序<span
									class="required" aria-required="true"> *</span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="排序" th:field="*{goodsManageSort}" id="goods_goodsManageSort" />
								</div>
							</div>

						</div>
						<div class="form-actions fluid">
							<div class="col-md-offset-3 col-md-9">
								<button type="button" class="btn blue" id="bt_submitSKU" name="button_submit" onclick="upload()">提交并设置SKU</button>
								<button type="button" class="btn blue" id="bt_submit" name="button_submit" onclick="upload()">提交</button>
							</div>
						</div>
					</form>
<!-- 			 style="display:none"		 -->
					<div >
					<!-- <table id="sku_list_goodsSN" style="display:none">
					<tr th:each="data : ${skuList}">
						<td th:text="${data.sku_goodsSN}"></td>
					</tr>
					</table>
					
					<table id="sku_list_price" style="display:none">
					<tr th:each="data : ${skuList}">
						<td th:text="${data.goodsPrice}"></td>
					</tr>
					</table>
					
				 <table id="sku_list_num" style="display:none">
					<tr th:each="data : ${skuList}">
						<td th:text="${data.goodsNum}"></td>
					</tr>
					</table>
				
				<table id="sku_list_shapeCode" style="display:none">
					<tr th:each="data : ${skuList}">
						<td th:text="${data.shapeCode}"></td>
					</tr>
					</table> -->
					<table id="sku_list_goodsAttrList" style="display:none">
					<tr th:each="data : ${goodsAttrList}">
						<td th:text="${data}"></td>
					</tr>
					</table>
					<table id="sku_list_SelectList" style="display:none">
					<tr th:each="data : ${onlyList}">
						<td th:text="${data}"></td>
					</tr>
					</table>	
					<table id="sku_list_checkBoxList" style="display:none">
					<tr th:each="data: ${attrList}">
						<td  th:text="${data}"></td>
					</tr>
					</table>
				</div>	
				</div>
			</div>
			
<table>

<div id="goodshow" class="white_content"> 
	<a href="javascript:void(0)" onclick="document.getElementById('goodshow').style.display='none';document.getElementById('fade').style.display='none'">
   	<img id="goodsPic_display" style="width: 80%; height: 80%;" th:if="${goods.goodsPic != null}" th:src="${goods.goodsPic}" />
	 </a>
</div>

<div id="thumbshow" class="white_content"> 
	<a href="javascript:void(0)" onclick="document.getElementById('thumbshow').style.display='none';document.getElementById('fade').style.display='none'"> 
	<img id="thumbGoodsPic_display" style="width: 80%; height: 80%;" th:if="${goods.thumbGoodsPic != null}" th:src="${goods.thumbGoodsPic}" />
	</a>
</div> 

<div id="longshow" class="white_content"> 
	<a href="javascript:void(0)" onclick="document.getElementById('longshow').style.display='none';document.getElementById('fade').style.display='none'"> 
    <img id="longGoodsPic_display" style="width: 80%; height: 80%;" th:if="${goods.longGoodsPic != null}" th:src="${goods.longGoodsPic}" />
    </a>
</div>  
</table>	
		
		</div>	
	</div>
</body>
</html>


<script th:inline="javascript">
	/*<![CDATA[*/
	  
	KindEditor.ready(function(K) {
		K.create('#textarea_content', {
			uploadJson : '/upload/GOODS',
			allowFileManager : false
		});
	});
	var _ztree=$('#category_tree').jstree({
        "core" : {
            'data' : {'url' : function (node) {return '/tree/category';}}
        }
    });
	    $('#category_tree').on('select_node.jstree', function(e,data) { 
	    	check(data.node.id);
	    });
	function check(id){
		if(id==0){
			alert("不能选择顶级分类");
			return false;
		}
		$.ajax({
            url: '/goods/goods/list/',
            type: 'post',
            data: {'id': id},
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            error: function () {
                alert('出错');
            },
            success: function (data) {
            	//var colorval = document.getElementById("attrMapOneColor").value;
            	
            }
        }).done(function( html ) {
		    $("#div_sku_grid").html( html );
		    if($("#cateId").val() != null && $("#cateId").val() !=""){
		    	alert("此分类下有子类，不能添加商品");
		    }else{
		    	$("#categoryId option").each(function() { this.selected = (this.value == id); });
	    		$("#categoryId").change();
	    		$("#tree_modal").modal('hide');
		    }
		  });
	
	} 
	
	    var result;
	    function getCategoryById(id,categories){   	
	    	$(categories).each(function() { 
	    		if(this.id == id)result = this; 
	    		console.log(this.id);
		    	if(result){
		    		console.log('find it' + result);
		    		return result;
		    	}else{
		    		console.log('not find ,try sub cat' + result);
		    		result = getCategoryById(id,this.children);
		    		return result;
		    	}
	    	});
			return result;
	    }
	    function check2(checkId){
	    	var currentId = $("#categoryId").val();
			if($("#id").val() == 0){
				return true;
			}
	    	var thisCategory = getCategoryById(checkId,$('#category_tree').jstree().get_json()[0].children);
	    	var thisSubCategories = [];
	    	//console.log(thisCategory);
	    	addSubCategoriesToArray(thisCategory,thisSubCategories);
	    	//console.log(thisSubCategories);
	    	
	    	var checkPassed = true;
	    	$(thisSubCategories).each(function() {
	    		if(currentId == this){
	    			alert("不能选择自身子类");
	    			checkPassed = false;
	    		}
	    	});
	    	
	    	return checkPassed;
	    }
	    function addSubCategoriesToArray(category,array){
	    	//console.log(category.children);
	    	if(category.children){
		    	$(category.children).each(function() {
		    		console.log(this);
		    		array[array.length] = this.id;	 
		    		console.log(this.children);   		
		    		if(this.children)addSubCategoriesToArray(this.children,array);
		    	});
	    	}
	    }
	
	
	function handleAutoThumb(checked)
	{
	    document.forms['theForm'].elements['thumbPic'].disabled = checked;
	}

	$(document).ready(function(){
		/* $("input[name='goodsColorIdList']:checked").click();
		$("input[name='goodsSizeIdList']:checked").click(); */
	//alert($("input[name='goodsColorIdList']:checked").length);
		if($("input[name='goodsColorIdList']:checked").length >0 || $("input[name='goodsSizeIdList']:checked").length >0){
			$("#bt_submit").hide();
	    	$("#bt_submitSKU").show();
		}else{
			$("#bt_submit").show();
	    	$("#bt_submitSKU").hide();
		}
		 /* if($("#attrMapOneColor").val() != null){
		    	$("#bt_submit").hide();
		    	$("#bt_submitSKU").show();
		    }else{
		    	$("#bt_submitSKU").hide();
		    	$("#bt_submit").show();
		    } */
		
		$('#treebutton').html($("#categoryId").find("option:selected").text() + '<i class="fa fa-angle-down"></i>');
		$("#categoryId").change(function(){$('#treebutton').html($("#categoryId").find("option:selected").text() + '<i class="fa fa-angle-down"></i>'); });
		
			$(".div_contentlist span").trigger("change");
		
    	
		if($("#checkVal").attr("checked")=="checked"){
			document.forms['theForm'].elements['thumbPic'].disabled = true;
		}

			var goodsValue =  $("#goodsValue").val();
			var longValue =  $("#longValue").val();
			var thumbValue =  $("#thumbValue").val();

		   if(goodsValue.length == 0){
		    document.getElementById("goodpic").style.display="none";
		   }else{
		    document.getElementById("goodpic").style.display=" ";
		   }
		   
		   if(longValue.length == 0){
		    document.getElementById("longpic").style.display="none";	
		   }else{
		    document.getElementById("longpic").style.display=" ";
		   }
		   
		   if(thumbValue.length == 0){
		    document.getElementById("thumbpic").style.display="none";	
		   }else{
		    document.getElementById("thumbpic").style.display=" ";
		   }


		 $("#goods_form_check").validate({
	         rules:{
	             name:{
	            	 required:true,
	            	 maxlength:200
	             },
	             title:{
	            	 maxlength:200 
	             },
	             goodsSN:{
	            	 required:true,
					 remote:{
							url:'/goods/goods/verifyGoodsSN?goodsId='+$('#goodsId').val(),
						},
					maxlength:10	
	             },
	             shopPrice:{
	                 required:true,
	                 number:true,
	                 max:999999999.00
	                 
	             },
	             marketPrice:{
	                 required:true,
	                 number:true,
	                 max:999999999.00
	             },
	             content:{
	                 required:true
	             },
	             goodsStore:{
	                 required:true,
	                 number:true
	             },
	             reservedStore:{
	                 required:true,
	                 number:true,
	                 digits:true
	             },
	             virtualSales:{
	                 required:true,
	                 number:true,
	                 digits:true
	             },
	             realSales:{
	                 required:true,
	                 number:true,
	                 digits:true
	             },
	             goodsManageSort:{
	            	 required:true,
	                 digits:true,  
	                 range:[0,254]   
	             }
	             
	             
	             
	         },
	         messages:{
	             name:{
	                 required:"请输入商品名称",
	                 maxlength:'商品名称长度不可超过200'
	             },
	             title:{
	                 maxlength:'促销标题长度不可超过200'
	             },
	             goodsSN:{
	            	 remote:'<a onclick="editGoodSN()">商品货号重复,点击进行编辑</a>',
					 required:'请输入商品货号',
					 maxlength:'商品货号长度不可超过10'
	             },
	             shopPrice:{
	                 required:"请输入本店售价",
	                 number:"请输入正确的金额",
	                 max:'本店售价最大值为99999999.99且必须为数字'
	             },
	             marketPrice:{
	                 required:"请输入市场售价",
	                 number:"请输入正确的金额",
	                 max:'市场售价最大值为99999999.99且必须为数字'
	             },
	             content:{
	                 required:"请输入商品详情"
	             },
	             goodsStore:{
	                 required:"请输入库存数量",
	                 number:"请输入正确的数量"
	             },
	             reservedStore:{
	            	 required:"请输入库存数量",
	                 number:"请输入正确的数量",
	                 digits:"请输入正确的数量"
	             },
	             virtualSales:{
	            	 required:"请输入库存数量",
	                 number:"请输入正确的数量",
	                 digits:"请输入正确的数量"
	             },
	             realSales:{
	            	 required:"请输入库存数量",
	                 number:"请输入正确的数量",
	                 digits:"请输入正确的数量"
	             },
	             goodsManageSort:{
	            	 required:"请输入商品排序",
	                 maxlength:"最大值不能超过254"
	                 
	             }
	             
	             
	         }
	     });

		$("#sku_list_goodsAttrList td").each(function(i){
		 		$(".imgShow"+i).attr("src",$(this).html()); 
   		});
		
		$("#sku_list_checkBoxList td").each(function(j,checktx){
		$(".div_contentlist input[type=checkbox]:checked").each(function (i,item) {
			if(i == j){
				$("."+item.id).attr("type","text");
				$("."+item.id).attr("value",$(checktx).html());
			}
   		}); 
				
		});
		 
		$("#sku_list_SelectList td").each(function(i){
			$(".slelect_checked option[value='"+$(this).html()+"']").attr("selected", "selected");
		});
		 

	});


	
	function editGoodSN(){
		var goodsNum = document.getElementById("goods_goodsSN").value;
		BOSS.remoteCall('goods/goods/editBygoodsSN/'+goodsNum,$('#check_goodsSN_form'));
	
	}
	
    function fileChange(target,val) {
    	var goodpic;
        if(val == 1){
        	goodpic = $("#goodsp").val();  
        }else if(val == 2){
        	goodpic = $("#thumbPic").val();
        }else if(val == 3 ){
        	goodpic = $("#longsp").val(); 
        }
    	
    	if(!/\.(gif|jpg|jpeg|png|gif|jpg|png)$/i.test(goodpic)){
              alert("图片类型必须是.gif,jpeg,jpg,png中的一种");
              if(val == 1){
              	goodpic = $("#goodsp").val("");  
              }else if(val == 2){
              	goodpic = $("#thumbPic").val("");
              }else if(val == 3 ){
              	goodpic = $("#longsp").val(""); 
              }
              
       }else{ 
    	 
        var fileSize = 0;  
        if (!target.files) {
            var filePath = target.value;
            var fileSystem = new ActiveXObject("Scripting.FileSystemObject");   
            var file = fileSystem.GetFile (filePath);
            fileSize = file.Size;
        } else {
            fileSize = target.files[0].size;
        }

        if(fileSize == 0 || fileSize >=5120000){
        	alert("文件大小不能为0，或者大于5MB");
        	if(val == 1){
              	goodpic = $("#goodsp").val("");  
              }else if(val == 2){
              	goodpic = $("#thumbPic").val("");
              }else if(val == 3 ){
              	goodpic = $("#longsp").val(""); 
              }
        }
    }
    
    }

    function upload(){
    	KindEditor.sync('#textarea_content');
    	if($("#goodsPic_display").attr("src") == null || $("#goodsPic_display").attr("src") ==""){
    		var satus = $("#checkVal").attr("checked");
       	 if(satus == "checked"){
       		 var goodsp = $("#goodsp").val();
       		 var longsp = $("#longsp").val();
       		 if(goodsp == "" || goodsp == null){
       	    		alert("商品图片为选中，请选择上传的图片！")
       	    		return false;
       	    	}
       		 
       		 if(longsp == "" || longsp == null){
       			 	alert("商品长图为选中，请选择上传的图片！")
       			 	return false;
       		 }
       	 }else{
       		 var goodsp = $("#goodsp").val();
       		 var longsp = $("#longsp").val();
       		 var thumbPic = $("#thumbPic").val();
       		 if(goodsp == "" || goodsp == null){
    	    		alert("商品图片为选中，请选择上传的图片！")
    	    		return false;
    	    	}
       		 if(thumbPic == "" || thumbPic == null){
     			 	alert("商品缩略图未选中，请选择上传的图片！")
     			 	return false;
     		 	}
    		 	if(longsp == "" || longsp == null){
    			 	alert("商品长图为选中，请选择上传的图片！")
    			 	return false;
    		 	}
    		 	
       	 }
    	}
    	
    	
    	
    	if($("input[name='goodsColorIdList']").length >0 && $("input[name='goodsSizeIdList']").length >0){
    		
    		if($("input[name='goodsColorIdList']:checked").length>0 && $("input[name='goodsSizeIdList']:checked").length ==0){
    			alert("商品规格复选框，必须都要选择，否则无效")
    			return false;
    		}else if($("input[name='goodsColorIdList']:checked").length==0 && $("input[name='goodsSizeIdList']:checked").length >0){
    			alert("商品规格复选框，必须都要选择，否则无效")
    			return false;
    		}else{
    			checkPic();
    		}
    	}else{
    			checkPic();	
    	}
    	
    	
    }
    
    function checkPic(){
    	/* var color = document.getElementById("attrMapOneColor");
		if(color=="颜色"){ */
			
			if($("#sample_editable_2 tr td:first").html() == null || $("#sample_editable_2 tr td:first").html() == ""){
				$("#goods_form_check").submit();
			}else{
				var all_empty = true;
				var none_empty = true;
				
				$("#sample_editable_2 tr input").each(function(i){
		    		if($("#imgShow"+i).val()  == null || $("#imgShow"+i).val() == ""){
		    			none_empty = false;
		    			
		    		}else{
		    			all_empty = false;
		    		}
				});
				if(all_empty){
					$("#goods_form_check").submit();
				}
				if(none_empty){
					$("#goods_form_check").submit();
				}
				if(!all_empty && !none_empty){
					alert("颜色图片要么都上传，要么都不上传");
	    			$("#sample_editable_2 tr input").each(function(i,item){
	    				$("#imgShow"+i).attr("value","");
	    			});
				}
			}
		/* }else{
			$("#goods_form_check").submit();
		} */
    }
    
    
	
	/*]]>*/
</script>